//
// Created by Administrator on 2022/6/15.
//

#ifndef RAPIDSVN_WIN_MAINDIALOG_H
#define RAPIDSVN_WIN_MAINDIALOG_H

#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include <wx/dialog.h>
#include <wx/sizer.h>
#include <wx/button.h>
#include <wx/statline.h>
#include <wx/stattext.h>
#include <wx/listbox.h>
#include <wx/filepicker.h>
#include <mysql.h>
#include <vector>

using namespace std;

//class DelayThread;
//struct Item;
class PostFileWorker;

class MainDialog : public wxFrame
{
    friend class PostFileWorker;
public:
    /*
     * data update
     * objects
     * View
     * getCurrentValue
     * load the table
     * build the view items
     * dialog
     * 只有value是变化的
     */
    explicit MainDialog( wxWindow *parent = nullptr );
    ~MainDialog() override;

    void post();
    WXLRESULT MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) override ;
private:
    vector<wxPanel*> panels;
    bool should_delete_file;

    void buildMenu();
    void OnHello(wxCommandEvent& event);
    void OnExit(wxCommandEvent& event);
    void OnAbout(wxCommandEvent& event);
    void OnFilePickerChange(wxFileDirPickerEvent& event);

    void BuildView( );
    void addMySqlLog( wxString log );

    void OnRunDelay( wxCommandEvent& event );
    void OnStartPost( wxCommandEvent& event );
    void OnCBFileDelete( wxCommandEvent& event );

    int idx;
    void request();
    /*
     * layout:
     *  list: sizeBox(v)
     *      panel
     *          sizeBox(v)
     *              //sizeBox(h)
     *                  title//, wxSpace, input:value
     *              statusCtrl
     */
    wxPanel *m_panel;
    //listBox sizer
    wxBoxSizer *panelRootBoxSizer;
    wxBoxSizer *dialogRootBoxSizer;
    wxScrolledWindow* m_listbox;
    wxTextCtrl* m_logBox;
    wxFilePickerCtrl* m_filePicker1;
    wxCheckBox *cb_isDelete;
    wxTimer *m_timer;
    //void OnClickItem(wxCommandEvent& event);
    virtual void OnClickItem( wxMouseEvent& event );

    void OnClose( wxCloseEvent&  event );

    void OnActionEvent(wxCommandEvent &event);
    void OnTimer( wxTimerEvent& event );
private:

    wxGauge *m_gauge1;
    wxButton *test_delay_button;
    wxButton *start_post_button;
    //wxThread *networkMonitor;
    //
    wxThread *postFileWorker;
    //DelayThread* delayThread;

    MYSQL *conn_ptr;

    void addLog( const wxString& log );
    void addEventLog( const wxString& log );
    //Item* item;
DECLARE_EVENT_TABLE()
};
enum
{
    ID_Hello = 1
};


#endif //RAPIDSVN_WIN_MAINDIALOG_H
